# -*- coding:utf-8 -*-
# @FileName  :dhcc_ent_2_authorize.py
# @Time      :2020/11/27 11:07
# @Author    :Zhoujirong
# @Desc      : 授权信息维护
import datetime
import time
import parameterized
from biz.flow.ent_report import EntReportRequest
from biz.flow.ent_authorize import EntAuthorizeRequest
from biz.cases.base_case import BaseCase
from common.log import Log
from common.params_operator import Param


class TestEntAuthorize(BaseCase):
    '''授权文档管理'''
    data_file_name = 'ent_authorize_data.yaml'

    @classmethod
    def setUpClass(cls):
        cls.cookie = BaseCase().get_token()
        cls.id = BaseCase().ent_archive_create()

    @parameterized.parameterized.expand(Param.from_excel('authorize_data_pic.xls'))
    def test_aupload(self,file,fileType,md5,needMd5,check,desc):
        self._testMethodDoc = desc # 用例描述
        ret = EntAuthorizeRequest.upload(file,fileType,self.id,md5,needMd5,self.cookie)
        Log.info(ret)
        check=int(check)
        self.assertEqual(check,ret.code)

    def test_barchive_getpage(self):
        '''全条件检索'''
        curPage = self.file_data.get('curPage')
        maxSize = self.file_data.get('maxSize')
        search_EQ_enterpriseName = self.file_data.get('search_EQ_enterpriseName')
        search_EQ_signCode = self.file_data.get('search_EQ_signCode')
        search_EQ_uniformSocialCredCode = self.file_data.get('search_EQ_uniformSocialCredCode')
        search_EQ_orgInstCode = self.file_data.get('search_EQ_orgInstCode')
        search_EQ_archiveType = self.file_data.get('search_EQ_archiveType')
        search_EQ_creator = self.file_data.get('search_EQ_creator')
        search_IN_ownOrg = self.file_data.get('search_IN_ownOrg')
        search_GTE_startDate_DATE = datetime.date.today()
        search_LTE_expireDate_DATE = datetime.date.today()
        EQ_queryNum = self.file_data.get('EQ_queryNum')
        ret = EntAuthorizeRequest.archive_getpage(curPage,
                            maxSize, search_EQ_enterpriseName,
                            search_EQ_signCode,search_EQ_uniformSocialCredCode,search_EQ_orgInstCode,
                            search_EQ_archiveType,search_EQ_creator,
                            search_IN_ownOrg,search_GTE_startDate_DATE,
                            search_LTE_expireDate_DATE,EQ_queryNum,self.cookie)
        Log.info(ret)
        self.assertIsNotNone(ret.list)

    def test_cfind_archive(self):
        '''查看有哪些授权文件'''
        ret = EntAuthorizeRequest.find_archive(self.id,self.cookie)
        Log.info(ret)
        self.assertEqual(4,len(ret))

    def test_dfindbyid(self):
        '''授权文件详情'''
        ret = EntAuthorizeRequest.findbyid(self.id,self.cookie)
        Log.info(ret)
        self.assertEqual(self.id,ret.id,'接口返回与预期不符')

    def test_earchive_update(self):
        '''编辑授权档案'''
        archiveType = self.file_data.get('archiveType')
        creatTime = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        creator = self.file_data.get('creator')
        ext1 = self.file_data.get('ext1')
        ext2 = self.file_data.get('ext2')
        ext3 = self.file_data.get('ext3')
        ext4 = self.file_data.get('ext4')
        ext5 = self.file_data.get('ext5')
        ext6 = self.file_data.get('ext6')
        extendDate = datetime.date.today()
        note = self.file_data.get('note_update')
        operTime = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        operationIdentifier = self.file_data.get('operationIdentifier')
        operator = self.file_data.get('operator')
        quantity = self.file_data.get('quantity')
        queryNum = self.file_data.get('queryNum')
        remarks = self.file_data.get('remarks')
        reqId = self.file_data.get('reqId')
        resCode = self.file_data.get('resCode')
        resMsg = self.file_data.get('resMsg')
        serialNumber = self.file_data.get('serialNumber')
        startDate = datetime.date.today()
        status = self.file_data.get('status')
        paperFileId = self.file_data.get('paperFileId')
        fileDescribe = self.file_data.get('fileDescribe')
        enterpriseName = self.file_data.get('enterpriseName')
        signCode = self.file_data.get('signCode')
        dsRegiNo = self.file_data.get('dsRegiNo')
        uniformSocialCredCode = self.file_data.get('uniformSocialCredCode')
        expireDate = datetime.date.today()
        frgCorpNo = self.file_data.get('frgCorpNo')
        gsRegiNo = self.file_data.get('gsRegiNo')
        operOrg = self.file_data.get('operOrg')
        orgCreditCode = self.file_data.get('orgCreditCode')
        orgInstCode = self.file_data.get('orgInstCode')
        ownOrg = self.file_data.get('ownOrg')
        regiTypeCode = self.file_data.get('regiTypeCode')

        ret = EntAuthorizeRequest.archive_update(archiveType,enterpriseName,
                            creatTime,creator,signCode,
                            dsRegiNo,uniformSocialCredCode,
                            expireDate,ext1,
                            ext2,ext3,
                            ext4,ext5,
                            ext6,extendDate,
                            frgCorpNo,gsRegiNo,
                            self.id,note,
                            operTime,operationIdentifier,
                            operator,operOrg,orgCreditCode,
                            quantity,orgInstCode,
                            queryNum,remarks,ownOrg,
                            reqId,resCode,regiTypeCode,
                            resMsg,serialNumber,
                            startDate,status,
                            paperFileId,fileDescribe,self.cookie)
        Log.info(ret)
        self.assertEqual('00000000',ret.code)

    def test_esave_paper(self):
        '''保存授权文档'''
        paperfileid = self.file_data.get('paperFileId')
        filedescribe = self.file_data.get('fileDescribe')
        archiveid = self.id
        ret = EntReportRequest.ent_save_paper(paperfileid, filedescribe, archiveid, self.cookie)
        Log.info(ret)
        self.assertEqual('00000000', ret.code, '接口调用失败')
        return archiveid

    # 添加纸质授权档案并删除流程
    def archive_create_paper(self):
        '''添加授纸质权档案'''
        archiveType = self.file_data.get('archiveType')
        Num = self.file_data.get('Num')
        enterpriseName = self.file_data.get('enterpriseName_paper')
        signCode = self.file_data.get('signCode')
        orgInstCode = self.file_data.get('orgInstCode')
        uniformSocialCredCode = self.file_data.get('uniformSocialCredCode')
        startDate = datetime.date.today()
        expireDate = datetime.date.today()
        note = self.file_data.get('note')
        paperFileId = self.file_data.get('paperfileid_paper')
        fileDescribe = self.file_data.get('filedescribe_paper')
        ret = EntReportRequest.ent_archive_create(archiveType,Num,enterpriseName,signCode,orgInstCode,
                           uniformSocialCredCode,startDate,expireDate,note,
                           paperFileId,fileDescribe, self.cookie)
        Log.info(ret)
        self.assertEqual('00000000', ret.code)
        return ret.msg

    def save_paper(self):
        '''保存授权文档'''
        paperfileid = self.file_data.get('paperfileid_paper')
        filedescribe = self.file_data.get('filedescribe_paper')
        archiveid = self.archive_create_paper()
        ret = EntReportRequest.ent_save_paper(paperfileid, filedescribe, archiveid, self.cookie)
        Log.info(ret)
        self.assertEqual('00000000', ret.code, '接口调用失败')
        return archiveid

    def test_farchive_del(self):
        '''删除授权信息和档案'''
        id = self.save_paper()
        ret = EntAuthorizeRequest.archive_del(id,self.cookie)
        Log.info(ret)
        self.assertEqual('00000000',ret.code)
        self.assertIn('删除授权信息成功',ret.msg)

    #带电子档案待审批查询报告
    def ent_inquire(self):
        '''获取审批id'''
        enterpriseName = self.file_data.get('enterpriseName')
        signCode = self.file_data.get('signCode')
        uniformSocialCredCode = self.file_data.get('uniformSocialCredCode')
        orgInstCode = self.file_data.get('orgInstCode')
        assocbsnssData = self.file_data.get('assocbsnssData')
        note = self.file_data.get('note')
        queryFormat = '00'
        resultType = self.file_data.get('resultType')
        qryReason = self.file_data.get('qryReason')
        queryControlWarningType = self.file_data.get('queryControlWarningType')
        serialNumber = self.file_data.get('serialNumber')
        archiveId = self.id
        rekUser = self.file_data.get('rekUser')
        rekPasword = self.file_data.get('rekPasword')
        checkWay = self.file_data.get('checkWay')
        autharchiveId = archiveId
        ret = EntReportRequest.ent_inquire(enterpriseName,
                                           signCode,
                                           uniformSocialCredCode,
                                           orgInstCode,
                                           assocbsnssData,
                                           note,
                                           queryFormat,
                                           resultType,
                                           qryReason,
                                           queryControlWarningType,
                                           serialNumber,
                                           archiveId,
                                           rekUser,
                                           rekPasword,
                                           checkWay,
                                           autharchiveId, self.cookie)
        Log.info(ret)
        self.assertIsNotNone(ret.resultMsg)
        return ret.checkId

    def test_gshowreport(self):
        enterpriseName = self.file_data.get('enterpriseName')
        signCode = self.file_data.get('signCode')
        uniformSocialCredCode = self.file_data.get('uniformSocialCredCode')
        orgInstCode = self.file_data.get('orgInstCode')
        assocbsnssData = self.file_data.get('assocbsnssData')
        note = self.file_data.get('note')
        queryFormat = '00'
        resultType = self.file_data.get('resultType')
        qryReason = self.file_data.get('qryReason')
        queryControlWarningType = self.file_data.get('queryControlWarningType')
        serialNumber = self.file_data.get('serialNumber')
        checkId = self.ent_inquire()
        archiveId = self.id
        rekUser = self.file_data.get('rekUser')
        checkWay = self.file_data.get('checkWay')
        autharchiveId = archiveId
        ret = EntReportRequest.ent_show_report(enterpriseName,
                            signCode,
                            uniformSocialCredCode,
                            orgInstCode,
                            assocbsnssData,
                            note,
                            queryFormat,
                            resultType,
                            qryReason,
                            queryControlWarningType,
                            serialNumber,
                            archiveId,
                            autharchiveId,
                            checkId,
                            rekUser,
                            checkWay,self.cookie)
        Log.info(ret)
        self.assertIsNotNone(ret.url)












if __name__ == "__main__":
    pass